home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Src Code / AXISINCR.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  5.4 KB  |  215 lines

  1. {**********************************************}
  2. {   TAxisIncrement Dialog Editor               }
  3. {   Copyright (c) 1996-98 David Berneda        }
  4. {**********************************************}
  5. {$I teedefs.inc}
  6. unit AxisIncr;
  7.  
  8. interface
  9.  
  10. uses
  11.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  12.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Chart, Teengine, TeeProcs;
  13.  
  14. type
  15.   TAxisIncrement = class(TForm)
  16.     RadioGroup1: TRadioGroup;
  17.     CBSteps: TComboBox;
  18.     ECustom: TEdit;
  19.     BitBtn1: TButton;
  20.     BitBtn2: TButton;
  21.     Label1: TLabel;
  22.     CBExact: TCheckBox;
  23.     procedure FormShow(Sender: TObject);
  24.     procedure RadioGroup1Click(Sender: TObject);
  25.     procedure BitBtn1Click(Sender: TObject);
  26.     procedure CBExactClick(Sender: TObject);
  27.     procedure CBStepsChange(Sender: TObject);
  28.   private
  29.     { Private declarations }
  30.     Procedure SetEditText;
  31.   public
  32.     { Public declarations }
  33.     IsDateTime : Boolean;
  34.     IsExact    : Boolean;
  35.     Increment  : Double;
  36.     IStep      : TDateTimeStep;
  37.   end;
  38.  
  39. Function GetIncrementText( AOwner:TComponent;
  40.                            Const Increment:Double;
  41.                            IsDateTime,
  42.                            ExactDateTime:Boolean;
  43.                            Const AFormat:String):String;
  44. implementation
  45.  
  46. {$R *.DFM}
  47.  
  48. Uses TeeConst;
  49.  
  50. procedure TAxisIncrement.FormShow(Sender: TObject);
  51. var tmpDif:Integer;
  52. begin
  53.   Screen.Cursor:=crDefault;
  54.   CBExact.Visible:=IsDateTime;
  55.   CBExact.Enabled:=RadioGroup1.ItemIndex=0;
  56.   CBExact.Checked:=IsExact;
  57.   If IsDateTime then
  58.   begin
  59.     ECustom.Hint:=TeeMsg_EnterDateTime;
  60.     SetEditText;
  61.     if IsExact and (IStep<>dtNone) then
  62.     Begin
  63.       RadioGroup1.ItemIndex:=0;
  64.       CBSteps.ItemIndex:=Ord(IStep);
  65.       ECustom.Text:='';
  66.       ECustom.Enabled:=False;
  67.       CBSteps.SetFocus;
  68.     end
  69.     else
  70.     begin
  71.       RadioGroup1.ItemIndex:=1;
  72.       CBSteps.ItemIndex:=-1;
  73.     end;
  74.   end
  75.   else
  76.   begin
  77.     CBSteps.Visible:=False;
  78.     RadioGroup1.Visible:=False;
  79.     RadioGroup1.ItemIndex:=1;
  80.     ECustom.Hint:='';
  81.     ECustom.Text:=FloatToStr(Increment);
  82.     tmpDif:=ECustom.Top-Label1.Top;
  83.     ECustom.Top:=BitBtn1.Top;
  84.     Label1.Top:=ECustom.Top-tmpDif;
  85.     ECustom.SetFocus;
  86.   end;
  87. end;
  88.  
  89. Procedure TAxisIncrement.SetEditText;
  90. Begin
  91.   if Increment<=0 then ECustom.Text:=TimeToStr(DateTimeStep[dtOneSecond])
  92.   else
  93.   if Increment>=1 then
  94.   Begin
  95.     ECustom.Text:=FloatToStr(Int(Increment));
  96.     if Frac(Increment)<>0 then
  97.        ECustom.Text:=ECustom.Text+' '+TimeToStr(Frac(Increment));
  98.   end
  99.   else ECustom.Text:=TimeToStr(Increment);
  100. end;
  101.  
  102. procedure TAxisIncrement.RadioGroup1Click(Sender: TObject);
  103.  
  104.   Procedure EnableControls(Value:Boolean);
  105.   begin
  106.     ECustom.Enabled:=not Value;
  107.     CBExact.Checked:=Value;
  108.     IsExact:=Value;
  109.     CBExact.Enabled:=Value;
  110.     CBSteps.Enabled:=Value;
  111.   end;
  112.  
  113. begin
  114.   Case RadioGroup1.ItemIndex of
  115.     0: Begin
  116.          EnableControls(True);
  117.          if IStep<>dtNone then
  118.             CBSteps.ItemIndex:=Ord(IStep)
  119.          else
  120.             CBSteps.ItemIndex:=0;
  121.          CBSteps.SetFocus;
  122.        end;
  123.     1: Begin
  124.          EnableControls(False);
  125.          SetEditText;
  126.          ECustom.SetFocus;
  127.        end;
  128.   end;
  129. end;
  130.  
  131. procedure TAxisIncrement.BitBtn1Click(Sender: TObject);
  132. var i:Longint;
  133. begin
  134.   try
  135.     if IsDateTime then
  136.     Begin
  137.       if RadioGroup1.ItemIndex=0 then
  138.          Increment:=DateTimeStep[TDateTimeStep(CBSteps.ItemIndex)]
  139.       else
  140.       With ECustom do
  141.       Begin
  142.         i:=AnsiPos(' ',Text);
  143.         if i=0 then
  144.         try
  145.           Increment:=StrToTime(Text);
  146.         except
  147.           on Exception do Increment:=StrToFloat(Text);
  148.         end
  149.         else Increment:=StrToFloat(Copy(Text,1,i-1))+
  150.                         StrToTime(Copy(Text,i+1,255));
  151.       end;
  152.     end
  153.     else Increment:=StrToFloat(ECustom.Text);
  154.     ModalResult:=mrOk;
  155.   except
  156.     on E:Exception do
  157.        ShowMessage(Format(TeeMsg_IncorrectMaxMinValue,[E.Message]));
  158.   end;
  159. end;
  160.  
  161. procedure TAxisIncrement.CBExactClick(Sender: TObject);
  162. begin
  163.   IsExact:=CBExact.Checked;
  164.   if not IsExact then
  165.   begin
  166.     RadioGroup1.ItemIndex:=1;
  167.     ECustom.Enabled:=True;
  168.     SetEditText;
  169.     ECustom.SetFocus;
  170.   end;
  171. end;
  172.  
  173. procedure TAxisIncrement.CBStepsChange(Sender: TObject);
  174. begin
  175.   IStep:=TDateTimeStep(CBSteps.ItemIndex);
  176. end;
  177.  
  178. Function GetIncrementText( AOwner:TComponent;
  179.                            Const Increment:Double;
  180.                            IsDateTime,
  181.                            ExactDateTime:Boolean;
  182.                            Const AFormat:String):String;
  183.  
  184.   Function GetDateTimeStepText(tmp:TDateTimeStep):String;
  185.   begin
  186.     result:='';
  187.     With TAxisIncrement.Create(AOwner) do
  188.     try
  189.       result:=CBSteps.Items[Ord(tmp)];
  190.     finally
  191.       Free;
  192.     end;
  193.   end;
  194.  
  195. var tmp:TDateTimeStep;
  196. begin
  197.   if IsDateTime then
  198.   begin
  199.     tmp:=FindDateTimeStep(Increment);
  200.     if ExactDateTime and (tmp<>dtNone) then result:=GetDateTimeStepText(tmp)
  201.     else
  202.     if Increment<=0 then result:=TimeToStr(DateTimeStep[dtOneSecond])
  203.     else
  204.     if Increment<=1 then result:=TimeToStr(Increment)
  205.     else
  206.     Begin
  207.       result:=FloatToStr(Int(Increment));
  208.       if Frac(Increment)<>0 then result:=result+' '+TimeToStr(Frac(Increment));
  209.     end;
  210.   end
  211.   else result:=FormatFloat(AFormat,Increment);
  212. end;
  213.  
  214. end.
  215.